/**2013-4-10
 zhangqj
 * 
 */
package com.data;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zhangqj
 *2013-4-10
 */
public class DataMeta {

	private DatabaseMetaData DBMD=null;
	private ResultSetMetaData data=null;
//	private RSet rs=null;
	private Connection conns=null;
	public DatabaseMetaData getDBMetaData(Connection conn){
		try {
			DBMD=conn.getMetaData();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return DBMD;
	}
	public DatabaseMetaData getDBMetaData(){
		try {
			DBMD=conns.getMetaData();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return DBMD;
	}
	
	public ResultSetMetaData getRSMDdata(ResultSet rs){
		try {
			data=rs.getMetaData();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return data;
	}
	
	public int CountColumn(ResultSet rs){
 
		int count = 0;
		try {
			count = this.getRSMDdata(rs).getColumnCount();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}
	/**
	 * get  the name of column 
	 */
	public Map<Integer ,String> getColumnName(ResultSet rs){
		Map<Integer,String> _map=new HashMap<Integer,String>();
		int count=this.CountColumn(rs);
		for(int i=0;i<count;i++){
			String name=null;
			try {
				 name=this.getRSMDdata(rs).getColumnName(i);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			_map.put(i, name);
		}
		return  _map;		
	}
}
